<?php
!$opration && $opration = 'list';
$forum = $forums = array();
cpheader();
if ($opration=='toggle_post'){
	$forum['fid'] = max(array(0,intval(getpc('fid'))));
	$forum = $db->get_one("SELECT fid,poststatus FROM sdw_forum WHERE fid=$forum[fid]");
	$forum['poststatus'] = $forum['poststatus'] == 1 ? 0 : 1;
	$db->query("UPDATE sdw_forum SET poststatus=$forum[poststatus] WHERE fid=$forum[fid]");
	dexit($forum['poststatus']);
}
if ($opration=='toggle_reply'){
	$forum['fid'] = max(array(0,intval(getpc('fid'))));
	$forum = $db->get_one("SELECT fid,replystatus FROM sdw_forum WHERE fid=$forum[fid]");
	$forum['replystatus'] = $forum['replystatus'] == 1 ? 0 : 1;
	$db->query("UPDATE sdw_forum SET replystatus=$forum[replystatus] WHERE fid=$forum[fid]");
	dexit($forum['poststatus']);
}
if ($opration == 'save'){
	$_POST['fid'] = isset($_POST['fid']) ? intval($_POST['fid']) : 0;
	$forum = $_POST['forumnew'];
	if ($_POST['fid']>0){
		$db->update('sdw_forum',$forum,'fid='.$_POST['fid']);
		$links[0] = array('text'=>$LANG['back_list'],'href'=>'index.php?action=forum');
		showmsg('modi_success',0,$links);
	}else {
		$db->insert('sdw_forum',$forum,true);
		$links[0] = array('text'=>$LANG['back_list'],'href'=>'index.php?action=forum');
		showmsg('save_success',0,$links);
	}
}
if ($opration == 'edit'){
	$forum['fid'] = max(array(0,intval(getpc('fid'))));
	$smarty->assign('forum',$db->get_one("SELECT * FROM sdw_forum WHERE fid=$forum[fid]"));
}
if ($opration == 'drop'){
	$forum['fid'] = isset($_GET['id']) ? trim($_GET['id']) : 0;
	$db->query("DELETE FROM sdw_forum WHERE fid IN ($forum[fid])");
	$opration = 'list';
}
if ($opration == 'list'){
	$query = $db->query("SELECT * FROM sdw_forum ORDER BY displayorder ASC,fid ASC");
	while ($result = $db->fetch_array($query)){
		$forums[] = $result;
	}
	$smarty->assign('forums',$forums);
}
$smarty->assign('opration',$opration);
$smarty->display('admin_forum.htm');
cpfooter();
?>